package com.mayikt.utils;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @ClassName LogBlockingQueue
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class LogBlockingQueue {
    private static final int maxCapacity = 256;
    private static ArrayBlockingQueue<String>
            logBlockingQueue =
            new ArrayBlockingQueue<String>(maxCapacity);



    /**
     * 向队列中存放日志内容
     * 业务线程
     *
     * @param log
     * @return
     */
    public static synchronized boolean addLog(String log) {
        return logBlockingQueue.offer(log);

    }

    /**
     * 向队列中取出内容
     * 日志线程 假设缓冲区 每次4条消息
     *
     * @return
     */
    public static String getLog() {
        //poll从队列中取出 日志 直接将他从队列移除\ 取5条 10条
        logBlockingQueue.poll();

        return logBlockingQueue.poll();
    }

}
